package cn.sharp.bbs.controller;

import cn.sharp.bbs.common.Result;
import cn.sharp.bbs.dao.gen.LabelMapper;
import cn.sharp.bbs.entity.BO.CurrentUser;
import cn.sharp.bbs.entity.DO.Label;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 杨择润
 * @create 2022-07-15 14:48
 */
@RestController
@RequestMapping("/admin/labels")
public class TabsController {
    @Resource
    LabelMapper labelMapper;
    //获取标签列表
    @ResponseBody
    @PostMapping("/selectalltabs")
    public Result getalltabs(){
        List<Label> a=labelMapper.selectAll();
        return Result.success(a);
    }
    //新建标签
    @PostMapping("/newtabs")
    public Result createtabs(@RequestAttribute("CurrentUser") CurrentUser user, @RequestBody Label label){
        label.setUserId(user.getU_id());
        //获取当前时间值
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        label.setTime(date);
        labelMapper.insert(label);
        return Result.success();
    }
    //删除标签
    @PostMapping("/deletetabs")
    public Result deletetabs( @RequestBody Long id){
        labelMapper.deleteByPrimaryKey(id);
        return Result.success();
    }
    //修改标签
    @PostMapping("/updatetabs")
    public Result updatetabs(@RequestAttribute("CurrentUser") CurrentUser user, @RequestBody Label label){
        label.setUserId(user.getU_id());

        Date date = new Date(System.currentTimeMillis());
        label.setTime(date);
        labelMapper.updateByPrimaryKey(label);
        return Result.success();
    }



}
